package com.coder.rental.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coder.rental.entity.CarBrand;
import com.coder.rental.entity.CarInfo;
import com.coder.rental.mapper.CarBrandMapper;
import com.coder.rental.mapper.CarInfoMapper;
import com.coder.rental.service.ICarBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 汽车品牌 服务实现类
 * </p>
 *
 * @author zhaojj
 * @since 2025-01-10
 */
@Service
public class CarBrandServiceImpl extends ServiceImpl<CarBrandMapper, CarBrand> implements ICarBrandService {

    @Resource
    private CarInfoMapper carInfoMapper;
    @Override
    public Page<CarBrand> searchByPage(Page<CarBrand> page, CarBrand carBrand) {
        return baseMapper.searchByPage(page,carBrand);
    }

    @Override
    public List<CarBrand> selectByMakerId(Integer makerId) {
        QueryWrapper<CarBrand> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mid",makerId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public boolean hasCar(Integer brandId) {
        QueryWrapper<CarInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("brand_id",brandId);
        return carInfoMapper.selectCount(queryWrapper) > 0;
    }

    @Override
    public List<CarBrand> selectAll() {
        return baseMapper.selectAll();
    }
}
